package test1;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;

    String[] boyfaces={"风流倜傥","气宇轩昂","长相平平","风度翩翩","惨不忍睹","长相清秀","三头六臂"};
    String[] girlfaces={"闭月羞花","沉鱼落雁","倾国倾城","风姿卓越","忧国忧民","面容娇羞","五官清秀"};

    String[] attacks_desc={
            "%s使出一招【寒枪连袭】，直击对面胸膛。",
            "%s使出一招【夺命十三枪】，连续打出十三道攻击，直逼对手。",
            "%s双手合十，蓄力一击使出【如来神掌】，闪电般向对手袭去",
            "%s大喝一声，用出【河东狮吼】，以超强声波扑面而至",
            "%s直接跳身而起，使出【全力一脚】，踹向对手的面门",
            "%s向天一指，借来【天雷】，劈向对方",
    };

    String[] injured_desc={
            "%s直接瞬闪，躲过攻击",
            "%s接了对方一击，吐了一口血",
            "%s被击倒，颤颤巍巍的站了起来",
            "%s脸色一下惨白，连退好几步",
            "%s全力防守，但仍然身受重伤",
            "%s鲜血狂喷，濒临危险",
            "%s支撑不住，倒地不起",
    };
    public Role() {

    }

    public Role(String name, int blood,char gender) {
        this.name = name;
        this.blood = blood;
        this.gender=gender;
        setFace(gender);
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r=new Random();
        if(gender=='男'){
            int index=r.nextInt(boyfaces.length);
            this.face=boyfaces[index];
        }else if(gender=='女'){
            int index=r.nextInt(girlfaces.length);
            this.face=girlfaces[index];
        }else {
            this.face = "猪狗不如";
        }

    }

    public String getName() {
        return name;
    }

    public int getBlood() {
        return blood;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public void attack(Role role){
        Random r=new Random();
        int index=r.nextInt(attacks_desc.length);
        String KunFu=attacks_desc[index];
        System.out.printf(KunFu,this.getName());
        System.out.println();
        int hurt = r.nextInt(20)+1;
        int remainBlood=role.getBlood()-hurt;
        remainBlood=remainBlood<0 ? 0 : remainBlood;
        role.setBlood(remainBlood);
        if(remainBlood>90){
            System.out.printf(injured_desc[0],role.getName());
        }else if(remainBlood>80&&remainBlood<=90){
            System.out.printf(injured_desc[1],role.getName());
        }else if(remainBlood>70&&remainBlood<=80){
            System.out.printf(injured_desc[2],role.getName());
        }else if(remainBlood>60&&remainBlood<=70){
            System.out.printf(injured_desc[3],role.getName());
        }else if(remainBlood>40&&remainBlood<=60){
            System.out.printf(injured_desc[4],role.getName());
        }else if(remainBlood>20&&remainBlood<=40){
            System.out.printf(injured_desc[5],role.getName());
        }else if(remainBlood>0&&remainBlood<=20){
            System.out.printf(injured_desc[6],role.getName());
        }
        System.out.println();
    }

    public void showRoleInfo(){
        System.out.println("姓名为："+getName());
        System.out.println("血量为："+getBlood());
        System.out.println("性别为："+getGender());
        System.out.println("长相为："+getFace());
    }

}
